package com.yujinglin.airline;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class airlineMapper extends Mapper<LongWritable, Text, IntWritable, airlineWritable> {

    @Override
    protected void map(LongWritable key,  @NotNull Text value, Context context) throws IOException, InterruptedException {

        String line = value.toString();
        String[] info = line.split(",");

        String airline="无数据";
        int flihtNumber =-1;
        String tailNumber="无数据";
        String orign="无数据";
        String destination="无数据";

        if (info.length >= 19 && !info[4].isEmpty() && !info[5].isEmpty() && !info[6].isEmpty()&& !info[7].isEmpty()&& !info[8].isEmpty()) {

                try{
                    airline = info[4];
                    flihtNumber= Integer.parseInt(info[5]);
                    tailNumber=info[6];
                    orign=info[7];
                    destination=info[8];
                }catch (Exception e){
                    e.printStackTrace();
                }

            context.write(new IntWritable(flihtNumber),new airlineWritable(airline,tailNumber,orign,destination));

        }





    }
}
